package com.yyy.instagram.Adaper;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.yyy.instagram.R;

/**
 * Created by qqqqqqq on 2016/10/9.
 */

public class NewsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    public final int LIKE_TWEET = 0;
    public final int SHARE_TWEET = 1;
    public final int FOLLOW_ME = 2;


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        switch (viewType){
            case LIKE_TWEET:{
                View view = LayoutInflater.from(parent.getContext())
                        .inflate(R.layout.item_news_like, parent, false);
                return new LikeViewHolder(view);
            }
            case SHARE_TWEET:{
                View view = LayoutInflater.from(parent.getContext())
                        .inflate(R.layout.item_news_share, parent, false);
                return new ShareViewHolder(view);
            }
            case FOLLOW_ME:{

                break;
            }
        }
        return null;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if(holder instanceof LikeViewHolder){
            LikeViewHolder likeholder = (LikeViewHolder) holder;
            likeholder.text.setText("XXzsunny 赞了你的照片 6天");
        }
        if(holder instanceof ShareViewHolder){
            ShareViewHolder likeholder = (ShareViewHolder) holder;
            likeholder.text.setText("Travel The World、柯震东kai 和其他用户分享了15张照片 6天");
        }
    }

    @Override
    public int getItemCount() {
        return 12;
    }

    @Override
    public int getItemViewType(int position) {
        if(position < 3){
            return LIKE_TWEET;
        }
        if(position == 3 || position == 4){
            return SHARE_TWEET;
        }
        if(position > 4){
            return LIKE_TWEET;
        }
        return LIKE_TWEET;
    }

    public class LikeViewHolder extends RecyclerView.ViewHolder{
        public SimpleDraweeView icon;
        public TextView text;
        public SimpleDraweeView image;
        public LikeViewHolder(View itemView) {
            super(itemView);
            icon = (SimpleDraweeView) itemView.findViewById(R.id.news_like_icon);
            text = (TextView) itemView.findViewById(R.id.news_like_text);
            image = (SimpleDraweeView) itemView.findViewById(R.id.news_like_image);
        }
    }

    public class ShareViewHolder extends RecyclerView.ViewHolder{
        public SimpleDraweeView icon;
        public TextView text;
        public ShareViewHolder(View itemView) {
            super(itemView);
            icon = (SimpleDraweeView) itemView.findViewById(R.id.news_share_icon);
            text = (TextView) itemView.findViewById(R.id.news_share_text);
        }
    }

}
